package net.tavion.angelboot.fegin.interceptor;


import com.fasterxml.jackson.databind.ObjectMapper;
import net.tavion.angelboot.fegin.logger.AccessLogger;
import net.tavion.angelboot.fegin.logger.FeignAccessLogger;
import org.aopalliance.intercept.MethodInterceptor;
import org.springframework.aop.support.AbstractPointcutAdvisor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ProxyFeignClientConfiguration {
    private AccessLogger feignAccessLogger;

    public ProxyFeignClientConfiguration(AccessLogger feignAccessLogger) {
        this.feignAccessLogger = feignAccessLogger;
    }

    @Bean
    public MethodInterceptor feignClientInterceptor() {
        return new FeignClientInterceptor(this.feignAccessLogger);
    }

    @Bean
    public AbstractPointcutAdvisor feignClientPointcutAdvisor() {
        BeanFactoryFeignClientPointcutAdvisor advisor = new BeanFactoryFeignClientPointcutAdvisor();
        advisor.setAdvice(this.feignClientInterceptor());
        advisor.setOrder(1);
        return advisor;
    }

//    @Bean
//    public  AccessLogger feignAccessLogger(){
//        return  new FeignAccessLogger(new ObjectMapper());
//
//    }
}